<?php

/**
 * @author: biggege
 * @since:  2021-08-05 16:58:01
 */
namespace App\Helpers;

trait ManageValidator
{

    protected $errorCode = 0;

    protected $errorMmessage = [];

    protected $validatorMessage = [
        'filled' => '请输入:attribute',
        'required' => '请输入:attribute',
        'required_with' => '请输入必填项',
        'required_without' => '请输入必填项',
        'required_without_all' => '请输入必填项',
        'integer' => '请核对:attribute类型',
        'string' => '请核对:attribute类型',
        'json' => '请核对:attribute类型',
        'array' => '请核对:attribute类型',
        'unique' => ':attribute不能重复',
        'min' => ':attribute超出范围',
        'max' => ':attribute超出范围',
        'date' => ':attribute是日期类型',
        'in' => ':attribute不在范围内',
    ];
    
    /**
     *
     * @return mixed
     */
    public function getErrorCode()
    {
        return $this->errorCode;
    }

    public function setErrorCode($errorCode)
    {
        $this->errorCode = $errorCode;
        return $this;
    }

    public function getErrorMessage()
    {
        return implode(' & ', $this->errorMmessage);
    }

    public function setErrorMessage($errorMmessage)
    {
        array_push($this->errorMmessage, $errorMmessage);
        return $this;
    }

    public function error($errorCode, $errorMmessage)
    {
        $this->setErrorCode($errorCode);
        $this->setErrorMessage($errorMmessage);
        return $this;
    }

    public function fails()
    {
        if ($this->getErrorCode() > 200) {
            return true;
        }
        return false;
    }
}